<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>《在Flutter中利用Firebase插件进行用户身份验证应用程序》 - Lucklyの博客 - 在阅读中遇见自己</title><meta name="Description" content="早起的年轻人做的网站"><meta property="og:title" content="《在Flutter中利用Firebase插件进行用户身份验证应用程序》" />
<meta property="og:description" content="
本文主要介绍使用 Firebase 和 Flutter 进行用户身份验证
" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" />
<meta property="og:image" content="https://luckly.work/logo.png"/>
<meta property="article:published_time" content="2021-07-17T23:26:57+08:00" />
<meta property="article:modified_time" content="2021-07-17T23:26:57+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://luckly.work/logo.png"/>

<meta name="twitter:title" content="《在Flutter中利用Firebase插件进行用户身份验证应用程序》"/>
<meta name="twitter:description" content="
本文主要介绍使用 Firebase 和 Flutter 进行用户身份验证
"/>
<meta name="application-name" content="LoveIt">
<meta name="apple-mobile-web-app-title" content="LoveIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" /><link rel="prev" href="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%B6%E4%BD%9C%E8%AE%A1%E6%97%B6%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" /><link rel="next" href="https://luckly.work/%E6%A1%88%E4%BE%8B%E5%88%86%E6%9E%901/" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/normalize.css@8.0.1/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.7.2/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "《在Flutter中利用Firebase插件进行用户身份验证应用程序》",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/luckly.work\/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F\/"
        },"image": [{
                            "@type": "ImageObject",
                            "url": "https:\/\/luckly.work\/images\/Apple-Devices-Preview.png",
                            "width":  3200 ,
                            "height":  2048 
                        }],"genre": "posts","keywords": "flutter","wordcount":  1627 ,
        "url": "https:\/\/luckly.work\/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F\/","datePublished": "2021-07-17T23:26:57+08:00","dateModified": "2021-07-17T23:26:57+08:00","license": "This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.","publisher": {
            "@type": "Organization",
            "name": "xxxx","logo": {
                    "@type": "ImageObject",
                    "url": "https:\/\/luckly.work\/images\/avatar.png",
                    "width":  528 ,
                    "height":  560 
                }},"author": {
                "@type": "Person",
                "name": "早起的年轻人"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="Lucklyの博客 - 在阅读中遇见自己"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span><span id="id-1" class="typeit"></span></a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/categories/flutter/"> Flutter </a><a class="menu-item" href="/categories/read/"> 读书笔记 </a><a class="menu-item" href="/categories/go/"> Go </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="/about/"> 关于 </a><a class="menu-item" href="https://github.com/ITmxs" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i> Github </a><a class="menu-item" href="/friend/"><i class='fas fa-user-friends'></i> 友链 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="Lucklyの博客 - 在阅读中遇见自己"><span class="header-title-pre"><i class='far fa-kiss-wink-heart fa-fw'></i></span><span id="id-2" class="typeit"></span></a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/categories/flutter/" title="">Flutter</a><a class="menu-item" href="/categories/read/" title="">读书笔记</a><a class="menu-item" href="/categories/go/" title="">Go</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="/about/" title="">关于</a><a class="menu-item" href="https://github.com/ITmxs" title="GitHub" rel="noopener noreffer" target="_blank"><i class='fab fa-github fa-fw'></i>Github</a><a class="menu-item" href="/friend/" title=""><i class='fas fa-user-friends'></i>友链</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">《在Flutter中利用Firebase插件进行用户身份验证应用程序》</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>早起的年轻人</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/flutter/"><i class="far fa-folder fa-fw"></i>Flutter</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2021-07-17">2021-07-17</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1627 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 4 分钟&nbsp;</div>
        </div><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"
        data-srcset="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png, https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png 1.5x, https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png 2x"
        data-sizes="auto"
        alt="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"
        title="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png" /></div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#火力基地它是什么">火力基地？它是什么</a>
      <ul>
        <li><a href="#设置我们的项目">设置我们的项目</a></li>
        <li><a href="#使用-firebase-和-flutter-匿名登录">使用 Firebase 和 Flutter 匿名登录</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><blockquote>
<p>本文主要介绍使用 Firebase 和 Flutter 进行用户身份验证</p>
</blockquote>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://luckly007.oss-cn-beijing.aliyuncs.com/img/image-20210717232730290.png"
        data-srcset="https://luckly007.oss-cn-beijing.aliyuncs.com/img/image-20210717232730290.png, https://luckly007.oss-cn-beijing.aliyuncs.com/img/image-20210717232730290.png 1.5x, https://luckly007.oss-cn-beijing.aliyuncs.com/img/image-20210717232730290.png 2x"
        data-sizes="auto"
        alt="https://luckly007.oss-cn-beijing.aliyuncs.com/img/image-20210717232730290.png"
        title="image-20210717232730290" /></p>
<p>在本教程中，我将向您展示如何使用 Firebase 和 Flutter 制作一个简单的用户身份验证系统。</p>
<p>在这篇文章中，我不打算解释什么是 Flutter 以及如何使用它，因此您至少应该具备 Flutter 和 Dart 编程语言的基础知识。</p>
<h1 id="火力基地它是什么">火力基地？它是什么</h1>
<p>在我们开始编码之前，让我们先谈谈 Firebase。Firebase 是由 Google 开发的用于创建移动和网络应用程序的平台。换句话说，它将帮助您更快、更轻松地构建应用程序的后端。Firebase 为开发人员提供许多服务，例如用户身份验证服务、firestore、实时数据库等等，这就是为什么如果您打算找工作或成为自由职业者，学习和掌握它是如此重要，因为许多客户都要求应用程序使用这项技术</p>
<h2 id="设置我们的项目">设置我们的项目</h2>
<p>首先，我邀请您通过以下链接注册 firebase： <a href="https://firebase.google.com/" target="_blank" rel="noopener noreffer">firebase.google.com</a></p>
<p>登录帐户后，只需在主页上创建一个新项目并按照以下步骤操作</p>
<p>1-创建一个新项目</p>
<p>[<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-OLDzwPg4CiI/X3N1wBs8QDI/AAAAAAAACpI/F4byNAbQLL8cKeUVQ1PHoHE-E0Nr-mUcgCLcBGAsYHQ/w640-h360/page1.PNG"
        data-srcset="https://1.bp.blogspot.com/-OLDzwPg4CiI/X3N1wBs8QDI/AAAAAAAACpI/F4byNAbQLL8cKeUVQ1PHoHE-E0Nr-mUcgCLcBGAsYHQ/w640-h360/page1.PNG, https://1.bp.blogspot.com/-OLDzwPg4CiI/X3N1wBs8QDI/AAAAAAAACpI/F4byNAbQLL8cKeUVQ1PHoHE-E0Nr-mUcgCLcBGAsYHQ/w640-h360/page1.PNG 1.5x, https://1.bp.blogspot.com/-OLDzwPg4CiI/X3N1wBs8QDI/AAAAAAAACpI/F4byNAbQLL8cKeUVQ1PHoHE-E0Nr-mUcgCLcBGAsYHQ/w640-h360/page1.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-OLDzwPg4CiI/X3N1wBs8QDI/AAAAAAAACpI/F4byNAbQLL8cKeUVQ1PHoHE-E0Nr-mUcgCLcBGAsYHQ/w640-h360/page1.PNG"
        title="img" /></p>
<p>2-按照以下步骤，为您的项目命名</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-Gg6xUGH2Zsg/X3N7tPEkmjI/AAAAAAAACpU/gxVhPFl0v9MxoQlaZxfUNEf80rGDS7xtgCLcBGAsYHQ/w640-h360/page2.PNG"
        data-srcset="https://1.bp.blogspot.com/-Gg6xUGH2Zsg/X3N7tPEkmjI/AAAAAAAACpU/gxVhPFl0v9MxoQlaZxfUNEf80rGDS7xtgCLcBGAsYHQ/w640-h360/page2.PNG, https://1.bp.blogspot.com/-Gg6xUGH2Zsg/X3N7tPEkmjI/AAAAAAAACpU/gxVhPFl0v9MxoQlaZxfUNEf80rGDS7xtgCLcBGAsYHQ/w640-h360/page2.PNG 1.5x, https://1.bp.blogspot.com/-Gg6xUGH2Zsg/X3N7tPEkmjI/AAAAAAAACpU/gxVhPFl0v9MxoQlaZxfUNEf80rGDS7xtgCLcBGAsYHQ/w640-h360/page2.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-Gg6xUGH2Zsg/X3N7tPEkmjI/AAAAAAAACpU/gxVhPFl0v9MxoQlaZxfUNEf80rGDS7xtgCLcBGAsYHQ/w640-h360/page2.PNG"
        title="img" /></p>
<p>3-您可以禁用 firebase 分析，因为我们不会在本教程中使用它</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-ewsbsr7KbFQ/X3N8BPteeMI/AAAAAAAACpc/6Om880_gqNwzBLW4U1VzcLOvXM2RnhZLgCLcBGAsYHQ/w640-h360/page3.PNG"
        data-srcset="https://1.bp.blogspot.com/-ewsbsr7KbFQ/X3N8BPteeMI/AAAAAAAACpc/6Om880_gqNwzBLW4U1VzcLOvXM2RnhZLgCLcBGAsYHQ/w640-h360/page3.PNG, https://1.bp.blogspot.com/-ewsbsr7KbFQ/X3N8BPteeMI/AAAAAAAACpc/6Om880_gqNwzBLW4U1VzcLOvXM2RnhZLgCLcBGAsYHQ/w640-h360/page3.PNG 1.5x, https://1.bp.blogspot.com/-ewsbsr7KbFQ/X3N8BPteeMI/AAAAAAAACpc/6Om880_gqNwzBLW4U1VzcLOvXM2RnhZLgCLcBGAsYHQ/w640-h360/page3.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-ewsbsr7KbFQ/X3N8BPteeMI/AAAAAAAACpc/6Om880_gqNwzBLW4U1VzcLOvXM2RnhZLgCLcBGAsYHQ/w640-h360/page3.PNG"
        title="img" /></p>
<p>4-等待它加载，然后单击继续</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-dxSDBfIvrq4/X3N-5Q4RBlI/AAAAAAAACpo/8Cjt5nixgNQbKrSPcALTGVQCrI3dM_XeACLcBGAsYHQ/w640-h360/page4.PNG"
        data-srcset="https://1.bp.blogspot.com/-dxSDBfIvrq4/X3N-5Q4RBlI/AAAAAAAACpo/8Cjt5nixgNQbKrSPcALTGVQCrI3dM_XeACLcBGAsYHQ/w640-h360/page4.PNG, https://1.bp.blogspot.com/-dxSDBfIvrq4/X3N-5Q4RBlI/AAAAAAAACpo/8Cjt5nixgNQbKrSPcALTGVQCrI3dM_XeACLcBGAsYHQ/w640-h360/page4.PNG 1.5x, https://1.bp.blogspot.com/-dxSDBfIvrq4/X3N-5Q4RBlI/AAAAAAAACpo/8Cjt5nixgNQbKrSPcALTGVQCrI3dM_XeACLcBGAsYHQ/w640-h360/page4.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-dxSDBfIvrq4/X3N-5Q4RBlI/AAAAAAAACpo/8Cjt5nixgNQbKrSPcALTGVQCrI3dM_XeACLcBGAsYHQ/w640-h360/page4.PNG"
        title="img" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-ylLNAXkL02g/X3OCRSkMfPI/AAAAAAAACp0/Y9fQzrBmOHEDP-IbDXqsCTNnULmEULZcQCLcBGAsYHQ/w640-h360/page5.PNG"
        data-srcset="https://1.bp.blogspot.com/-ylLNAXkL02g/X3OCRSkMfPI/AAAAAAAACp0/Y9fQzrBmOHEDP-IbDXqsCTNnULmEULZcQCLcBGAsYHQ/w640-h360/page5.PNG, https://1.bp.blogspot.com/-ylLNAXkL02g/X3OCRSkMfPI/AAAAAAAACp0/Y9fQzrBmOHEDP-IbDXqsCTNnULmEULZcQCLcBGAsYHQ/w640-h360/page5.PNG 1.5x, https://1.bp.blogspot.com/-ylLNAXkL02g/X3OCRSkMfPI/AAAAAAAACp0/Y9fQzrBmOHEDP-IbDXqsCTNnULmEULZcQCLcBGAsYHQ/w640-h360/page5.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-ylLNAXkL02g/X3OCRSkMfPI/AAAAAAAACp0/Y9fQzrBmOHEDP-IbDXqsCTNnULmEULZcQCLcBGAsYHQ/w640-h360/page5.PNG"
        title="img" /></p>
<p>5- 现在将打开一个新窗口。单击 android 图标按钮将您的 android 应用程序添加到 firebase</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/--rZy8OHE01s/X3OGVIgAElI/AAAAAAAACqA/oP2FTLp_HY4EHYuRB7MJKNM1wYpgD8WdgCLcBGAsYHQ/w640-h360/page6.PNG"
        data-srcset="https://1.bp.blogspot.com/--rZy8OHE01s/X3OGVIgAElI/AAAAAAAACqA/oP2FTLp_HY4EHYuRB7MJKNM1wYpgD8WdgCLcBGAsYHQ/w640-h360/page6.PNG, https://1.bp.blogspot.com/--rZy8OHE01s/X3OGVIgAElI/AAAAAAAACqA/oP2FTLp_HY4EHYuRB7MJKNM1wYpgD8WdgCLcBGAsYHQ/w640-h360/page6.PNG 1.5x, https://1.bp.blogspot.com/--rZy8OHE01s/X3OGVIgAElI/AAAAAAAACqA/oP2FTLp_HY4EHYuRB7MJKNM1wYpgD8WdgCLcBGAsYHQ/w640-h360/page6.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/--rZy8OHE01s/X3OGVIgAElI/AAAAAAAACqA/oP2FTLp_HY4EHYuRB7MJKNM1wYpgD8WdgCLcBGAsYHQ/w640-h360/page6.PNG"
        title="img" /></p>
<p>6- 为您的项目命名并按照步骤操作</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-8FqSP9LKe-0/X3ON0ckGgbI/AAAAAAAACqM/BD6GEXkd5E8XC3mhH3VnT12dRNp79FlHACLcBGAsYHQ/w640-h360/page8.PNG"
        data-srcset="https://1.bp.blogspot.com/-8FqSP9LKe-0/X3ON0ckGgbI/AAAAAAAACqM/BD6GEXkd5E8XC3mhH3VnT12dRNp79FlHACLcBGAsYHQ/w640-h360/page8.PNG, https://1.bp.blogspot.com/-8FqSP9LKe-0/X3ON0ckGgbI/AAAAAAAACqM/BD6GEXkd5E8XC3mhH3VnT12dRNp79FlHACLcBGAsYHQ/w640-h360/page8.PNG 1.5x, https://1.bp.blogspot.com/-8FqSP9LKe-0/X3ON0ckGgbI/AAAAAAAACqM/BD6GEXkd5E8XC3mhH3VnT12dRNp79FlHACLcBGAsYHQ/w640-h360/page8.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-8FqSP9LKe-0/X3ON0ckGgbI/AAAAAAAACqM/BD6GEXkd5E8XC3mhH3VnT12dRNp79FlHACLcBGAsYHQ/w640-h360/page8.PNG"
        title="img" /></p>
<p>对于应用程序 ID，您将在应用程序文件夹内的 build.gradle 文件中找到它[<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-CMBSH2BkcCU/X3OSs7DV1-I/AAAAAAAACqY/x7O5MYp4pNcHyCZ4EdVoBUq3at2FbsvwwCLcBGAsYHQ/w640-h460/page7.PNG"
        data-srcset="https://1.bp.blogspot.com/-CMBSH2BkcCU/X3OSs7DV1-I/AAAAAAAACqY/x7O5MYp4pNcHyCZ4EdVoBUq3at2FbsvwwCLcBGAsYHQ/w640-h460/page7.PNG, https://1.bp.blogspot.com/-CMBSH2BkcCU/X3OSs7DV1-I/AAAAAAAACqY/x7O5MYp4pNcHyCZ4EdVoBUq3at2FbsvwwCLcBGAsYHQ/w640-h460/page7.PNG 1.5x, https://1.bp.blogspot.com/-CMBSH2BkcCU/X3OSs7DV1-I/AAAAAAAACqY/x7O5MYp4pNcHyCZ4EdVoBUq3at2FbsvwwCLcBGAsYHQ/w640-h460/page7.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-CMBSH2BkcCU/X3OSs7DV1-I/AAAAAAAACqY/x7O5MYp4pNcHyCZ4EdVoBUq3at2FbsvwwCLcBGAsYHQ/w640-h460/page7.PNG"
        title="img" />]</p>
<p>现在继续其他步骤并仔细阅读文档和每个文件的位置，然后单击下一步并运行您的应用程序以在您的应用程序和服务器之间建立连接。建立连接后，我们必须在 pubspec.yaml 文件中添加身份验证包并开始编码</p>
<p>添加<a href="https://pub.dev/packages/firebase_auth" target="_blank" rel="noopener noreffer">firebase auth 包</a></p>
<p>在我们开始编写我们的应用程序之前，我们必须做最后一步。</p>
<p>打开您的 firebase 身份验证控制台，然后单击身份验证</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-8CpJdWGzyEs/X3OigwmNJ-I/AAAAAAAACqk/US7Eyi5poQ4AJDgvmLoAr62XWVTKZ_GtQCLcBGAsYHQ/w640-h360/page12.PNG"
        data-srcset="https://1.bp.blogspot.com/-8CpJdWGzyEs/X3OigwmNJ-I/AAAAAAAACqk/US7Eyi5poQ4AJDgvmLoAr62XWVTKZ_GtQCLcBGAsYHQ/w640-h360/page12.PNG, https://1.bp.blogspot.com/-8CpJdWGzyEs/X3OigwmNJ-I/AAAAAAAACqk/US7Eyi5poQ4AJDgvmLoAr62XWVTKZ_GtQCLcBGAsYHQ/w640-h360/page12.PNG 1.5x, https://1.bp.blogspot.com/-8CpJdWGzyEs/X3OigwmNJ-I/AAAAAAAACqk/US7Eyi5poQ4AJDgvmLoAr62XWVTKZ_GtQCLcBGAsYHQ/w640-h360/page12.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-8CpJdWGzyEs/X3OigwmNJ-I/AAAAAAAACqk/US7Eyi5poQ4AJDgvmLoAr62XWVTKZ_GtQCLcBGAsYHQ/w640-h360/page12.PNG"
        title="img" /></p>
<p>现在点击选择登录方法并选择电子邮件和密码</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-GarYhwxaRQU/X3Oj-Vj9cSI/AAAAAAAACqw/B2lWtG17JbM0rFtuRUjalcp_fQ5ueP-PQCLcBGAsYHQ/w640-h360/page13.PNG"
        data-srcset="https://1.bp.blogspot.com/-GarYhwxaRQU/X3Oj-Vj9cSI/AAAAAAAACqw/B2lWtG17JbM0rFtuRUjalcp_fQ5ueP-PQCLcBGAsYHQ/w640-h360/page13.PNG, https://1.bp.blogspot.com/-GarYhwxaRQU/X3Oj-Vj9cSI/AAAAAAAACqw/B2lWtG17JbM0rFtuRUjalcp_fQ5ueP-PQCLcBGAsYHQ/w640-h360/page13.PNG 1.5x, https://1.bp.blogspot.com/-GarYhwxaRQU/X3Oj-Vj9cSI/AAAAAAAACqw/B2lWtG17JbM0rFtuRUjalcp_fQ5ueP-PQCLcBGAsYHQ/w640-h360/page13.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-GarYhwxaRQU/X3Oj-Vj9cSI/AAAAAAAACqw/B2lWtG17JbM0rFtuRUjalcp_fQ5ueP-PQCLcBGAsYHQ/w640-h360/page13.PNG"
        title="img" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-FO2u4zS7u8s/X3OkdvD5n-I/AAAAAAAACq4/WEuE6ddYqkg29yWlvAUyur1k5g9LpJyHwCLcBGAsYHQ/w640-h360/page14.PNG"
        data-srcset="https://1.bp.blogspot.com/-FO2u4zS7u8s/X3OkdvD5n-I/AAAAAAAACq4/WEuE6ddYqkg29yWlvAUyur1k5g9LpJyHwCLcBGAsYHQ/w640-h360/page14.PNG, https://1.bp.blogspot.com/-FO2u4zS7u8s/X3OkdvD5n-I/AAAAAAAACq4/WEuE6ddYqkg29yWlvAUyur1k5g9LpJyHwCLcBGAsYHQ/w640-h360/page14.PNG 1.5x, https://1.bp.blogspot.com/-FO2u4zS7u8s/X3OkdvD5n-I/AAAAAAAACq4/WEuE6ddYqkg29yWlvAUyur1k5g9LpJyHwCLcBGAsYHQ/w640-h360/page14.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-FO2u4zS7u8s/X3OkdvD5n-I/AAAAAAAACq4/WEuE6ddYqkg29yWlvAUyur1k5g9LpJyHwCLcBGAsYHQ/w640-h360/page14.PNG"
        title="img" /></p>
<p>[<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://1.bp.blogspot.com/-quUA7feG4Y0/X3OlJ6YDH1I/AAAAAAAACrA/gefR8TRnSCMOxalLXwjeqC2IERENboVYQCLcBGAsYHQ/w640-h360/page15.PNG"
        data-srcset="https://1.bp.blogspot.com/-quUA7feG4Y0/X3OlJ6YDH1I/AAAAAAAACrA/gefR8TRnSCMOxalLXwjeqC2IERENboVYQCLcBGAsYHQ/w640-h360/page15.PNG, https://1.bp.blogspot.com/-quUA7feG4Y0/X3OlJ6YDH1I/AAAAAAAACrA/gefR8TRnSCMOxalLXwjeqC2IERENboVYQCLcBGAsYHQ/w640-h360/page15.PNG 1.5x, https://1.bp.blogspot.com/-quUA7feG4Y0/X3OlJ6YDH1I/AAAAAAAACrA/gefR8TRnSCMOxalLXwjeqC2IERENboVYQCLcBGAsYHQ/w640-h360/page15.PNG 2x"
        data-sizes="auto"
        alt="https://1.bp.blogspot.com/-quUA7feG4Y0/X3OlJ6YDH1I/AAAAAAAACrA/gefR8TRnSCMOxalLXwjeqC2IERENboVYQCLcBGAsYHQ/w640-h360/page15.PNG"
        title="img" /></p>
<p>在我们的签名方法列表的底部，您会找到一个名为“匿名登录”的方法，您可以启用它，因为我们将使用它来测试我们的应用程序。</p>
<p>现在设置过程已经完成，让我们开始编写我们的应用程序</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span><span class="lnt">47
</span><span class="lnt">48
</span><span class="lnt">49
</span><span class="lnt">50
</span><span class="lnt">51
</span><span class="lnt">52
</span><span class="lnt">53
</span><span class="lnt">54
</span><span class="lnt">55
</span><span class="lnt">56
</span><span class="lnt">57
</span><span class="lnt">58
</span><span class="lnt">59
</span><span class="lnt">60
</span><span class="lnt">61
</span><span class="lnt">62
</span><span class="lnt">63
</span><span class="lnt">64
</span><span class="lnt">65
</span><span class="lnt">66
</span><span class="lnt">67
</span><span class="lnt">68
</span><span class="lnt">69
</span><span class="lnt">70
</span><span class="lnt">71
</span><span class="lnt">72
</span><span class="lnt">73
</span><span class="lnt">74
</span><span class="lnt">75
</span><span class="lnt">76
</span><span class="lnt">77
</span><span class="lnt">78
</span><span class="lnt">79
</span><span class="lnt">80
</span><span class="lnt">81
</span><span class="lnt">82
</span><span class="lnt">83
</span><span class="lnt">84
</span><span class="lnt">85
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dart" data-lang="dart"><span class="k">import</span> <span class="s1">&#39;package:firebase_auth/firebase_auth.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;package:firebase_core/firebase_core.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;package:flutter/material.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;authsystem.dart&#39;</span><span class="p">;</span>

<span class="kd">class</span> <span class="nc">LoginPage</span> <span class="kd">extends</span> <span class="n">StatefulWidget</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">_LoginPageState</span> <span class="n">createState</span><span class="p">()</span> <span class="o">=&gt;</span> <span class="n">_LoginPageState</span><span class="p">();</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">_LoginPageState</span> <span class="kd">extends</span> <span class="n">State</span><span class="o">&lt;</span><span class="n">LoginPage</span><span class="o">&gt;</span> <span class="p">{</span>
  <span class="c1">//Instancite the FirebaseAuth
</span><span class="c1"></span>
  <span class="kd">var</span> <span class="n">_myEmailController</span> <span class="o">=</span> <span class="n">TextEditingController</span><span class="p">();</span>
  <span class="kd">var</span> <span class="n">_myPasswordController</span> <span class="o">=</span> <span class="n">TextEditingController</span><span class="p">();</span>

  <span class="err">@</span><span class="n">override</span>
  <span class="kt">void</span> <span class="n">dispose</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">_myEmailController</span><span class="p">.</span><span class="n">dispose</span><span class="p">();</span>
    <span class="n">_myPasswordController</span><span class="p">.</span><span class="n">dispose</span><span class="p">();</span>
    <span class="k">super</span><span class="p">.</span><span class="n">dispose</span><span class="p">();</span>
  <span class="p">}</span>

  <span class="err">@</span><span class="n">override</span>
  <span class="n">Widget</span> <span class="n">build</span><span class="p">(</span><span class="n">BuildContext</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">Scaffold</span><span class="p">(</span>
      <span class="nl">appBar:</span> <span class="n">AppBar</span><span class="p">(</span>
        <span class="nl">title:</span> <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;Login Firebase&#34;</span><span class="p">),</span>
      <span class="p">),</span>
      <span class="nl">body:</span> <span class="n">Padding</span><span class="p">(</span>
        <span class="nl">padding:</span> <span class="kd">const</span> <span class="n">EdgeInsets</span><span class="p">.</span><span class="n">all</span><span class="p">(</span><span class="m">24.0</span><span class="p">),</span>
        <span class="nl">child:</span> <span class="n">Column</span><span class="p">(</span>
          <span class="nl">children:</span> <span class="p">[</span>
            <span class="n">TextField</span><span class="p">(</span>
              <span class="nl">controller:</span> <span class="n">_myEmailController</span><span class="p">,</span>
              <span class="nl">decoration:</span> <span class="n">InputDecoration</span><span class="p">(</span>
                  <span class="nl">hintText:</span> <span class="s2">&#34;Email&#34;</span><span class="p">,</span>
                  <span class="nl">filled:</span> <span class="kc">true</span><span class="p">,</span>
                  <span class="nl">fillColor:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">grey</span><span class="p">[</span><span class="m">10</span><span class="p">],</span>
                  <span class="nl">border:</span> <span class="n">InputBorder</span><span class="p">.</span><span class="n">none</span><span class="p">),</span>
            <span class="p">),</span>
            <span class="n">SizedBox</span><span class="p">(</span>
              <span class="nl">height:</span> <span class="m">20.0</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">TextField</span><span class="p">(</span>
              <span class="nl">controller:</span> <span class="n">_myPasswordController</span><span class="p">,</span>
              <span class="nl">obscureText:</span> <span class="kc">true</span><span class="p">,</span>
              <span class="nl">decoration:</span> <span class="n">InputDecoration</span><span class="p">(</span>
                  <span class="nl">hintText:</span> <span class="s2">&#34;password&#34;</span><span class="p">,</span>
                  <span class="nl">filled:</span> <span class="kc">true</span><span class="p">,</span>
                  <span class="nl">fillColor:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">grey</span><span class="p">[</span><span class="m">10</span><span class="p">],</span>
                  <span class="nl">border:</span> <span class="n">InputBorder</span><span class="p">.</span><span class="n">none</span><span class="p">),</span>
            <span class="p">),</span>
            <span class="n">SizedBox</span><span class="p">(</span>
              <span class="nl">height:</span> <span class="m">20.0</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">Center</span><span class="p">(</span>
              <span class="nl">child:</span> <span class="n">RaisedButton</span><span class="p">(</span>
                <span class="nl">onPressed:</span> <span class="p">()</span> <span class="p">{</span>
                  <span class="n">print</span><span class="p">(</span><span class="s2">&#34;Email:</span><span class="si">${</span><span class="n">_myEmailController</span><span class="p">.</span><span class="n">text</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">);</span>
                  <span class="n">print</span><span class="p">(</span><span class="s2">&#34;Email:</span><span class="si">${</span><span class="n">_myPasswordController</span><span class="p">.</span><span class="n">text</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">);</span>
                  <span class="cm">/** Here we are going to place our sign in with email code */</span>
                <span class="p">},</span>
                <span class="nl">child:</span> <span class="n">Text</span><span class="p">(</span>
                  <span class="s2">&#34;Login&#34;</span><span class="p">,</span>
                  <span class="nl">style:</span> <span class="n">TextStyle</span><span class="p">(</span><span class="nl">color:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">white</span><span class="p">),</span>
                <span class="p">),</span>
                <span class="nl">color:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">amber</span><span class="p">,</span>
              <span class="p">),</span>
            <span class="p">),</span>
            <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;Or&#34;</span><span class="p">),</span>
            <span class="n">RaisedButton</span><span class="p">(</span>
              <span class="nl">onPressed:</span> <span class="p">()</span> <span class="p">{</span>
                <span class="cm">/** Here we are going place our Authentication System Code */</span>
              <span class="p">},</span>
              <span class="nl">child:</span> <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;sign in as guest&#34;</span><span class="p">),</span>
              <span class="nl">color:</span> <span class="n">Colors</span><span class="p">.</span><span class="n">amber</span><span class="p">,</span>
            <span class="p">)</span>
          <span class="p">],</span>
        <span class="p">),</span>
      <span class="p">),</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>

</code></pre></td></tr></table>
</div>
</div><p>现在让我们返回 main.dart 文件并添加一些代码，因为您可能知道，firebase 不断更新，在 2020 年的最新更新中，我们必须先初始化我们的应用程序，然后才能使用 firebase，这就是我们添加 firebase_core 包的原因在我们的应用程序中。所以我们必须创建一个 Future 构建器，让我们更容易捕捉错误</p>
<p>main.dart</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dart" data-lang="dart"><span class="k">import</span> <span class="s1">&#39;package:flutter/material.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;package:loginsys/authsystem.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;package:firebase_core/firebase_core.dart&#39;</span><span class="p">;</span>
<span class="k">import</span> <span class="s1">&#39;authpage.dart&#39;</span><span class="p">;</span>

<span class="kt">void</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
  <span class="n">runApp</span><span class="p">(</span><span class="n">MaterialApp</span><span class="p">(</span>
    <span class="nl">home:</span> <span class="n">AuthenticationExample</span><span class="p">(),</span>
  <span class="p">));</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">AuthenticationExample</span> <span class="kd">extends</span> <span class="n">StatefulWidget</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">_AuthenticationExampleState</span> <span class="n">createState</span><span class="p">()</span> <span class="o">=&gt;</span> <span class="n">_AuthenticationExampleState</span><span class="p">();</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">_AuthenticationExampleState</span> <span class="kd">extends</span> <span class="n">State</span><span class="o">&lt;</span><span class="n">AuthenticationExample</span><span class="o">&gt;</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">Widget</span> <span class="n">build</span><span class="p">(</span><span class="n">BuildContext</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">FutureBuilder</span><span class="p">(</span>
      <span class="nl">future:</span> <span class="n">Firebase</span><span class="p">.</span><span class="n">initializeApp</span><span class="p">(),</span>
      <span class="nl">builder:</span> <span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">snapshot</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">snapshot</span><span class="p">.</span><span class="n">hasError</span><span class="p">)</span> <span class="p">{</span>
          <span class="k">return</span> <span class="n">Center</span><span class="p">(</span>
            <span class="nl">child:</span> <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;Someting went Worng&#34;</span><span class="p">),</span>
          <span class="p">);</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">snapshot</span><span class="p">.</span><span class="n">connectionState</span> <span class="o">==</span> <span class="n">ConnectionState</span><span class="p">.</span><span class="n">done</span><span class="p">)</span> <span class="p">{</span>
          <span class="k">return</span> <span class="n">LoginPage</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="k">return</span> <span class="n">Center</span><span class="p">(</span>
          <span class="nl">child:</span> <span class="n">CircularProgressIndicator</span><span class="p">(),</span>
        <span class="p">);</span>
      <span class="p">},</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>

</code></pre></td></tr></table>
</div>
</div><p>现在我们初始化了我们的应用程序，并创建了我们的布局，它是我们的主要功能，即登录功能。</p>
<h2 id="使用-firebase-和-flutter-匿名登录">使用 Firebase 和 Flutter 匿名登录</h2>
<p>我们将从使用 firebase 登录的最简单方法开始，它是匿名登录或访客登录。这部分非常简单，首先，我们将创建一个 FirebaseAuth 实例，我们将使用 SignInAnonymously 方法</p>
<p>现在就在 intaite auth 注释之后添加这一行</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-fallback" data-lang="fallback">//Instanciate the AuthService Class
  final FirebaseAuth _auth = FirebaseAuth.instance;
</code></pre></td></tr></table>
</div>
</div><p>现在在我们匿名登录的 Raised 按钮中添加这个函数就在 OnPressed 方法中</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dart" data-lang="dart"><span class="cm">/** Here we are going place our Anonymous Authentication System Code */</span>
                <span class="n">_auth</span><span class="p">.</span><span class="n">signInAnonymously</span><span class="p">().</span><span class="n">then</span><span class="p">((</span><span class="n">UserCredential</span> <span class="n">user</span><span class="p">)</span> <span class="p">{</span>
                  <span class="n">Navigator</span><span class="p">.</span><span class="n">of</span><span class="p">(</span><span class="n">context</span><span class="p">).</span><span class="n">push</span><span class="p">(</span><span class="n">MaterialPageRoute</span><span class="p">(</span>
                    <span class="nl">builder:</span> <span class="p">(</span><span class="n">context</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="n">LandingPage</span><span class="p">(),</span>
                  <span class="p">));</span>
                <span class="p">});</span>

</code></pre></td></tr></table>
</div>
</div><p>最后让我们创建一个登陆页面功能，允许我们在登录时登陆</p>
<p>landingpage.dart</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-dart" data-lang="dart"><span class="k">import</span> <span class="s1">&#39;package:flutter/material.dart&#39;</span><span class="p">;</span>

<span class="kd">class</span> <span class="nc">LandingPage</span> <span class="kd">extends</span> <span class="n">StatefulWidget</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">_LandingPageState</span> <span class="n">createState</span><span class="p">()</span> <span class="o">=&gt;</span> <span class="n">_LandingPageState</span><span class="p">();</span>
<span class="p">}</span>

<span class="kd">class</span> <span class="nc">_LandingPageState</span> <span class="kd">extends</span> <span class="n">State</span><span class="o">&lt;</span><span class="n">LandingPage</span><span class="o">&gt;</span> <span class="p">{</span>
  <span class="err">@</span><span class="n">override</span>
  <span class="n">Widget</span> <span class="n">build</span><span class="p">(</span><span class="n">BuildContext</span> <span class="n">context</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="n">Scaffold</span><span class="p">(</span>
      <span class="nl">body:</span> <span class="n">Center</span><span class="p">(</span>
        <span class="nl">child:</span> <span class="n">Text</span><span class="p">(</span><span class="s2">&#34;Welcome Sir&#34;</span><span class="p">),</span>
      <span class="p">),</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>

</code></pre></td></tr></table>
</div>
</div><p>这就是我们的登录功能，如果您运行您的应用程序并单击以访客身份登录按钮，您将进入该页面，当您打开 Firebase 控制台时，您会发现一个新用户已添加到您的用户列表中</p>
<p>在下一个教程中，我们将看到如何使用电子邮件和密码登录，以及如何创建注册表和创建注册功能。</p></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2021-07-17</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中利用Firebase插件进行用户身份验证应用程序》" data-hashtags="flutter"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-hashtag="flutter"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Hacker News" data-sharer="hackernews" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中利用Firebase插件进行用户身份验证应用程序》"><i class="fab fa-hacker-news fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中利用Firebase插件进行用户身份验证应用程序》"><i data-svg-src="https://cdn.jsdelivr.net/npm/simple-icons@2.14.0/icons/line.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://luckly.work/%E5%9C%A8flutter%E4%B8%AD%E5%88%A9%E7%94%A8firebase%E6%8F%92%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%94%A8%E6%88%B7%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" data-title="《在Flutter中利用Firebase插件进行用户身份验证应用程序》" data-image="https://luckly007.oss-cn-beijing.aliyuncs.com/img/90c6cc12-742e-4c9f-b318-b912f163b8d0.png"><i class="fab fa-weibo fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/flutter/">flutter</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/%E5%9C%A8flutter%E4%B8%AD%E5%88%B6%E4%BD%9C%E8%AE%A1%E6%97%B6%E5%99%A8%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/" class="prev" rel="prev" title="《在Flutter中制作计时器应用程序》"><i class="fas fa-angle-left fa-fw"></i>《在Flutter中制作计时器应用程序》</a>
            <a href="/%E6%A1%88%E4%BE%8B%E5%88%86%E6%9E%901/" class="next" rel="next" title="《案例分析1》">《案例分析1》<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.79.1">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">早起的年轻人</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.css"><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/smooth-scroll@16.1.3/dist/smooth-scroll.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.37.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/algoliasearch@4.2.0/dist/algoliasearch-lite.umd.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.2.2/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sharer.js@0.4.0/sharer.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/typeit@7.0.4/dist/typeit.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":10},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"data":{"id-1":"早起的年轻人","id-2":"早起的年轻人"},"search":{"algoliaAppID":"PASDMWALPK","algoliaIndex":"index.zh-cn","algoliaSearchKey":"b42948e51daaa93df92381c8e2ac0f93","highlightTag":"em","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"algolia"},"typeit":{"cursorChar":"|","cursorSpeed":1000,"data":{"id-1":["id-1"],"id-2":["id-2"]},"duration":-1,"speed":100}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
